import axios from 'axios'
const baseURL= 'http://localhost:8888/api/private/v1/';
axios.defaults.baseURL = baseURL;
// axios拦截器
axios.interceptors.request.use(function (config) {
    // Do something before request is sent
    let token = localStorage.getItem('mytoken');
    if(token){
        config.headers['Authorization']=token
    }
    return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });
// 登录验证
export const checkUser = params => {
    return axios.post('login',params).then(res => res.data)
}
// 用户数据列表
export const getUserList = params => {
    return axios.get('users',params).then(res => res.data)
}
// 修改用户状态
export const changeUserState = params => {
    return axios.put(`users/${params.uId}/state/${params.type}`).then(res => res.data)
}
// 添加用户
export const addUser = params => {
    return axios.post('users',params).then(res => res.data)
}
// 根据id查询用户信息
export const getUserId = params => {
    return axios.get(`users/${params}`).then(res => res.data)
}
// 编辑用户信息
export const editUser = params => {
    return axios.put(`users/${params.id}`,params).then(res => res.data)
}
// 删除用户信息
export const deleteUser = params => {
    return axios.delete(`users/${params}`).then(res => res.data)
}
// 获取角色列表
export const getRoleList = params => {
    return axios.get('roles').then(res => res.data)
}
// 分配用户角色
export const AssignRoles = params => {
    return axios.put(`users/${params.id}/role`,{id:params.id,rid:params.rid}).then(res => res.data)
}